package com.ellricky.baselib.ui.order

import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.adapter.SmartViewHolder
import com.andr.common.util.ToastUtil
import com.ellricky.baselib.R
import com.ellricky.baselib.entity.ClassConsumeInfo
import com.ellricky.baselib.entity.ClassConsumeRecord
import com.ellricky.baselib.widget.DetailItemView
import java.lang.Exception

class ClassConsumeRecordAdapter :
    BaseRecyclerAdapter<ClassConsumeRecord>(R.layout.base_adapter_class_consume_record) {
    override fun onBindViewHolder(holder: SmartViewHolder, data: ClassConsumeRecord, p2: Int) {
        holder.itemView.findViewById<DetailItemView>(R.id.tv_teacher_name).also {
            it.value = data.teacher_name
        }
        holder.itemView.findViewById<DetailItemView>(R.id.tv_consume_number).also {
            it.value = data.course_quantity
        }
        holder.itemView.findViewById<DetailItemView>(R.id.tv_time).also {
            it.value = data.list_date
        }
        holder.itemView.findViewById<DetailItemView>(R.id.tv_class_name).also {
            it.value = data.course_sub.toString()
        }
        holder.itemView.findViewById<TextView>(R.id.tv_state_value).also {
            it.text = data.dic_name
            val drawable = it.background as? GradientDrawable
            try {
                drawable?.setColor(Color.parseColor(data.state_color))
            } catch (e: Exception) {
                ToastUtil.show(it.context, "解析颜色值发生错误")
                e.printStackTrace()
            }
        }

        holder.itemView.findViewById<TextView>(R.id.tv_upload_value).also {
            it.text = data.job_image
            val drawable = it.background as? GradientDrawable
            try {
                drawable?.setColor(Color.parseColor("#66CC66"))
            } catch (e: Exception) {
                ToastUtil.show(it.context, "解析颜色值发生错误")
                e.printStackTrace()
            }
        }
    }
}